package design_pattern.command;


import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;

public class XMLUtil {
    public static Object getBean() {
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();

            Document parse = builder.parse(new File("HzWork/src/main/java/design/command/bean.xml"));

            NodeList className = parse.getElementsByTagName("className");
            Node classNode = className.item(0).getFirstChild();
            String nodeValue = classNode.getNodeValue();

            Class<?> aClass = Class.forName(nodeValue);
            Object o = aClass.newInstance();
            return o;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
